import asyncio

from langchain_community.embeddings import ModelScopeEmbeddings


class EmbeddingsClient:
    _instance = None
    _lock = asyncio.Lock()

    @classmethod
    async def get_instance(cls) -> ModelScopeEmbeddings:
        async with cls._lock:
            if cls._instance is None:
                model_id = "./embeddings/nlp_gte_sentence-embedding_chinese-base"
                cls._instance = ModelScopeEmbeddings(model_id=model_id)
            return cls._instance
